package com.bjpowernode.crm.settings.web.interceptor;

import com.bjpowernode.crm.commons.contants.Constants;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 郭俊才
 * 2021/8/18
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object userInfo = session.getAttribute(Constants.MESSAGE_SESSION_NAME);
        String contextPath = request.getContextPath();
        if(userInfo == null){
//            ResultEntity.failed("权限不够，请先登录");
            response.sendRedirect(contextPath+"/");
//            request.getRequestDispatcher("/settings/qx/user/login.do").forward(request, response);
            return false;
        }
        return true;
    }
}
